<template>
  <el-dialog title="钉钉授权" :visible.sync="dialogVisible" width="340px">
    <div id="self_defined_element_common" class="self-defined-classname"></div>
  </el-dialog>
</template>

<script>
import { getAccessToken } from "@/utils/dingTalk.js";
import {apiGetDingtalkUserInfo} from '@/api/recharge.js'
export default {
  components: {},
  data() {
    return {
      dialogVisible: false,
    };
  },
  mounted() {},
  methods: {
    open(fn) {
      this.dialogVisible = true;
      this.$nextTick(() => {
        getAccessToken({
          domId:'self_defined_element_common',
          cb: (res) => {
            if (res.type == "success") {
              this.$emit("submit", {  authCode: res.authCode });
              apiGetDingtalkUserInfo(res.authCode).then((response) => {
                fn && fn({  authCode: res.authCode ,initiateDingtalkId:response.data});
              });
              this.dialogVisible = false;
            } else {
              this.dialogVisible = false;
            }
          },
        });
      });
    },
  },
};
</script>

